package com.rams.jhms.fs.xml;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;

public class XmlWorker {
	
	public void writeFile(File f, Document doc) throws IOException {
		XMLWriter writer = new XMLWriter(new FileWriter(f));
	    writer.write(doc);
	    writer.close();
	}

	public void writeFile(String path, Document doc) {
		
	}
	
	public Document readFile(File f) throws DocumentException {
		if (!f.exists())
			return null;
		return readFile(f.getPath());
	}
	
	public Document readFile(String path) throws DocumentException {
		SAXReader reader = new SAXReader();
		Document document = reader.read(path);
		return document;
	}
}
